using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDF.Data;
using DDF.Data.Providers;
using System.Data;
using System.Linq.Expressions;
using System.Configuration;
using ARR.Entities.Gateways;

namespace ARR.DataModel.Repositories
{
	public static partial class RangeReviewSetupRepository
	{
		private static string connString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
		
		public class RangeReviewSetupDbo : DatabaseObject
        {
            public RangeReviewSetupDbo()
            {
                Name = "RangeReviewSetup";
                GeneratedClassName = "RangeReviewSetup";
                SequenceName = "N/A";
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Id", ColumnType = "int", IsIdentity = true, IsNullable = false, Length = 4, Precision = 10, Scale = 0, GeneratedPropertyName = "Id" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "RangeReviewId", ColumnType = "int", IsIdentity = false, IsNullable = false, Length = 4, Precision = 10, Scale = 0, GeneratedPropertyName = "RangeReviewId" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "CategoryId", ColumnType = "smallint", IsIdentity = false, IsNullable = false, Length = 2, Precision = 5, Scale = 0, GeneratedPropertyName = "CategoryId" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Sales", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Sales" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "SKUs", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "SKUs" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Units", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Units" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Margin", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Margin" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Inventory", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Inventory" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Space", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Space" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Brand", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Brand" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Manufacturer", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Manufacturer" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Subcategory", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Subcategory" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Attribute1", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Attribute1" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Attribute2", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Attribute2" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Attribute3", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Attribute3" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Attribute4", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Attribute4" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Attribute5", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Attribute5" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "LinearMeters", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "LinearMeters" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "SquareMeters", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "SquareMeters" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "SpaceAnalysis", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "SpaceAnalysis" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "SpaceBrand", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "SpaceBrand" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "DynamicsBrand", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "DynamicsBrand" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "DynamicsManufacturer", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "DynamicsManufacturer" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Combos", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Combos" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "PIDiff", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "PIDiff" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Coverage", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Coverage" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Penetration", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Penetration" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Benchmarks", ColumnType = "bit", IsIdentity = false, IsNullable = false, Length = 1, Precision = 1, Scale = 0, GeneratedPropertyName = "Benchmarks" });
              
            }
        }
		
		public static List<RangeReviewSetupRow> Select(Expression<Func<RangeReviewSetupRow, bool>> expression)
        {
            List<RangeReviewSetupRow> rows = new List<RangeReviewSetupRow>();

            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                IDataReader reader = database.Select<RangeReviewSetupRow>(new RangeReviewSetupDbo(), expression);

                Load(reader, rows);
            }

            return rows;
        }
		
		public static List<RangeReviewSetupRow> Select()
		{
			List<RangeReviewSetupRow> rows = new List<RangeReviewSetupRow>();

			using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
			{
				IDataReader reader = database.Select<RangeReviewSetupRow>(new RangeReviewSetupDbo(), null);

				Load(reader, rows);
			}

			return rows;
		}
		
		public static List<RangeReviewSetupRow> PagedSelect(Expression<Func<RangeReviewSetupRow, bool>> filterExpression, Expression<Func<RangeReviewSetupRow, object>> orderByExpression, int pageNumber, int pageSize)
		{
			List<RangeReviewSetupRow> rows = new List<RangeReviewSetupRow>();
			
			using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
			{
				IDataReader reader = database.PagedSelect<RangeReviewSetupRow>(new RangeReviewSetupDbo(), filterExpression, orderByExpression, pageNumber, pageSize);

				Load(reader, rows);
			}

			return rows;
		}
		
		private static void Load(IDataReader reader, List<RangeReviewSetupRow> RangeReviewSetupList)
        {
            RangeReviewSetupRow row;

            while (reader.Read())
            {
                row = new RangeReviewSetupRow()
                {
					Id = Util.CastDbValue<int>(reader["Id"]),
					RangeReviewId = Util.CastDbValue<int>(reader["RangeReviewId"]),
					CategoryId = Util.CastDbValue<int>(reader["CategoryId"]),
					Sales = Util.CastDbValue<bool>(reader["Sales"]),
					SKUs = Util.CastDbValue<bool>(reader["SKUs"]),
					Units = Util.CastDbValue<bool>(reader["Units"]),
					Margin = Util.CastDbValue<bool>(reader["Margin"]),
					Inventory = Util.CastDbValue<bool>(reader["Inventory"]),
					Space = Util.CastDbValue<bool>(reader["Space"]),
					Brand = Util.CastDbValue<bool>(reader["Brand"]),
					Manufacturer = Util.CastDbValue<bool>(reader["Manufacturer"]),
					Subcategory = Util.CastDbValue<bool>(reader["Subcategory"]),
					Attribute1 = Util.CastDbValue<bool>(reader["Attribute1"]),
					Attribute2 = Util.CastDbValue<bool>(reader["Attribute2"]),
					Attribute3 = Util.CastDbValue<bool>(reader["Attribute3"]),
					Attribute4 = Util.CastDbValue<bool>(reader["Attribute4"]),
					Attribute5 = Util.CastDbValue<bool>(reader["Attribute5"]),
					LinearMeters = Util.CastDbValue<bool>(reader["LinearMeters"]),
					SquareMeters = Util.CastDbValue<bool>(reader["SquareMeters"]),
					SpaceAnalysis = Util.CastDbValue<bool>(reader["SpaceAnalysis"]),
					SpaceBrand = Util.CastDbValue<bool>(reader["SpaceBrand"]),
					DynamicsBrand = Util.CastDbValue<bool>(reader["DynamicsBrand"]),
					DynamicsManufacturer = Util.CastDbValue<bool>(reader["DynamicsManufacturer"]),
					Combos = Util.CastDbValue<bool>(reader["Combos"]),
					PIDiff = Util.CastDbValue<bool>(reader["PIDiff"]),
					Coverage = Util.CastDbValue<bool>(reader["Coverage"]),
					Penetration = Util.CastDbValue<bool>(reader["Penetration"]),
					Benchmarks = Util.CastDbValue<bool>(reader["Benchmarks"])
                };
                                
                RangeReviewSetupList.Add(row);
            }

            reader.Close();
        }

			
		public static void Insert(RangeReviewSetupRow row)
        {
            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                database.Insert<RangeReviewSetupRow>(new RangeReviewSetupDbo(), row);
            }
        }

		public static void Update(RangeReviewSetupRow row)
        {
            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                database.Update<RangeReviewSetupRow>(new RangeReviewSetupDbo(), row);
            }
        }

		public static void Delete(Expression<Func<RangeReviewSetupRow, bool>> expression)
        {
            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                database.Delete<RangeReviewSetupRow>(new RangeReviewSetupDbo(), expression);
            }
        }

	}
}
	
